package com.feign.wugongbang.controller;

import com.feign.wugongbang.entity.WgbErrorCollection;
import com.feign.wugongbang.entity.WgbFeedback;
import com.feign.wugongbang.service.ErrorCollctionService;
import com.feign.wugongbang.service.FeedbackService;
import com.feign.wugongbang.utils.BeanAndMapTranslate;
import com.feign.wugongbang.utils.Constants;
import com.feign.wugongbang.utils.PageInfo;
import feign.Headers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import static org.springframework.web.bind.annotation.RequestMethod.PUT;

/**
 * Created by Administrator on 2017/5/24.
 */
@RestController
@RequestMapping(value = Constants.CODE_VERSION + "/feedbacks")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public Object add(MultipartFile[] uploadfile, @RequestHeader(value = "USER_TOKEN") String userToken, WgbFeedback feedback) throws Exception {
        //TODO 只支持单文件上传
        return feedbackService.add(uploadfile != null && uploadfile.length > 0 ? uploadfile[0] : null,userToken,BeanAndMapTranslate.objectToMap(feedback));
    }

    @RequestMapping(value = "/findFeedbacks", method = RequestMethod.POST)
    public Object get(@RequestBody PageInfo pageInfo){
        //TODO FeignMultipartSupportConfig 有错误
        return feedbackService.get(pageInfo);
    }

    @RequestMapping(value = "/{id}", method = PUT)
    public Object update(@PathVariable int id){
        return feedbackService.update(id);
    }
}
